package com.kaisa.activity.fragment;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;

import com.kaisa.activity.R;
import com.kaisa.activity.adapter.SortAdapter;
import com.kaisa.activity.bean.SortBean;
import com.kaisa.activity.ui.AllGoActivity;
import com.kaisa.activity.ui.SearchCountriesActivity;
import com.kaisa.activity.ui.ShipActivity;
import com.kaisa.activity.ui.SortSearchActivity;
import com.kaisa.activity.ui.TravelActivity;
import com.kaisa.activity.ui.VisaActivity;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2015/12/12.
 * 快速分类
 */
@ContentView(R.layout.fragment_sort)
public class SortFragmeng extends BaseFragment {
    @ViewInject(R.id.et_sort_title)
    private Button sortSearch;
    @ViewInject(R.id.lv_sort)
    private ListView sortListView;

    private SortAdapter adapter;

    private List<SortBean> list = new ArrayList<SortBean>();
    private int[] imgs = {R.mipmap.group_pic2x,R.mipmap.holiday_pic2x,
            R.mipmap.holiday_pic2x2,R.mipmap.holiday_pic2x3,
            R.mipmap.cruises_pic2x,R.mipmap.visa_pic2x,
            R.mipmap.card_pic2x};
    private String[] titles = {"团队游","自由行","半自助","小旅行","游轮","签证","旅游卡"};
    private String[] contents = {"省时省心，专业安全","自由随性，乐享舒适","比参团自由，比自由省心",
            "周末小长假，说走就走","优质游轮，全球精选","快捷高效，专业无忧","让风景，成为最好的礼物"};


    public static final String SIGN_FREE = "861C144E19CB5DA43FC3351FC73997AD";
    public static final String SIGN_SELF = "0AC2D49AB3B7CC75AC1CAB2F602A352F";
    public static final String SIGN_SMAL = "798B68F1586352F3EE8D518B1774D914";

    public static SortFragmeng newInstance() {
        SortFragmeng fragment = new SortFragmeng();
        return fragment;
    }


    @Override
    public void initView() {
        adapter = new SortAdapter(list,getActivity());
        sortListView.addHeaderView(LayoutInflater.from(getActivity()).inflate(R.layout.sory_listview_top, null));
        sortListView.setAdapter(adapter);

        addListener();
    }

    private void addListener() {
        //头部搜索监听
        sortSearch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getContext(), SortSearchActivity.class);
                startActivity(intent);
            }
        });

        sortListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                switch (i-1) {
                    case 0:
                        Intent intent0 = new Intent(getActivity(), SearchCountriesActivity.class);
                        intent0.putExtra("queryKey","");
                        startActivity(intent0);
                        break;
                    case 1:
                        Intent intent1 = new Intent(getActivity(), AllGoActivity.class);
                        intent1.putExtra("sign",SIGN_FREE);
                        intent1.putExtra("proTypeId","1");
                        startActivity(intent1);
                        break;
                    case 2:
                        Intent intent2 = new Intent(getActivity(), AllGoActivity.class);
                        intent2.putExtra("sign",SIGN_SELF);
                        intent2.putExtra("proTypeId","2");
                        startActivity(intent2);
                        break;
                    case 3:
                        Intent intent3 = new Intent(getActivity(), AllGoActivity.class);
                        intent3.putExtra("sign",SIGN_SMAL);
                        intent3.putExtra("proTypeId","3");
                        startActivity(intent3);
                        break;
                    case 4:
                        Intent intent4 = new Intent(getActivity(), ShipActivity.class);
                        startActivity(intent4);
                        break;
                    case 5:
                        Intent intent5 = new Intent(getActivity(),VisaActivity.class);
                        startActivity(intent5);
                        break;
                    case 6:
                        Intent intent6 = new Intent(getActivity(),TravelActivity.class);
                        startActivity(intent6);
                        break;
                }
            }
        });
    }

    @Override
    public void initData() {
        for (int i = 0; i < imgs.length; i++) {
            SortBean bean = new SortBean();
            bean.setImgId(imgs[i]);
            bean.setTitle(titles[i]);
            bean.setContent(contents[i]);
            list.add(bean);
        }
        adapter.notifyDataSetChanged();
    }
}
